<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<md-dialog-content class="content">
  <md-tabs md-dynamic-height md-border-bottom>
    <md-tab label="Import file" ng-click="$ctrl.toggleTab()">
      <div class="import-file-drop-box">
        <input type="file" filecontent="$ctrl.importAPIFile.content" filename="$ctrl.importAPIFile.name" />
      </div>
    </md-tab>
    <md-tab label="Import from link" ng-click="$ctrl.toggleTab()">
      <div class="input-group import-file-from-url">
        <input class="form-control" ng-model="$ctrl.apiDescriptorURL" required type="url" placeholder="{{$ctrl.placeholder()}}" />
      </div>
      <md-radio-group ng-model="$ctrl.importURLType" style="margin: 0px 24px">
        <md-radio-button class="import-file-from-url" ng-repeat="type in $ctrl.importURLTypes" value="{{type.id}}"
          >{{type.name}}</md-radio-button
        >
      </md-radio-group>
    </md-tab>
  </md-tabs>

  <div class="gv-error-container">
    <gv-error error="$ctrl.error"></gv-error>
  </div>

  <div style="margin: 24px" ng-class="{'gv-swagger-conf-update': $ctrl.isForUpdate() }" layout="column" ng-if="$ctrl.isSwaggerImport()">
    <h4>{{($ctrl.isWsdl() ? 'WSDL' : 'Swagger')}} import configurations:</h4>
    <div class="gv-warn" style="padding-bottom: 10px" ng-show="$ctrl.isForUpdate()">
      This will overwrite the name, the description and the version.
    </div>
    <md-checkbox
      ng-model="$ctrl.importCreateDocumentation"
      aria-label="($ctrl.isForUpdate() ? 'Update' : 'Create') documentation pages"
      flex
      ng-change="$ctrl.updateWarnText()"
    >
      {{($ctrl.isForUpdate() ? 'Update' : 'Create')}} documentation
      <div class="ipsum" style="color: grey">
        {{($ctrl.isForUpdate() ? 'Update the' : 'Add a')}} documentation page with the content of the {{($ctrl.isWsdl() ? 'WSDL' :
        'swagger')}} descriptor.
      </div>
      <div class="gv-warn" ng-show="$ctrl.isForUpdate() && $ctrl.importCreateDocumentation">
        This will overwrite the swagger documentation if there is only one existing, or create it if it does not exist yet.
      </div>
    </md-checkbox>
    <md-checkbox
      ng-model="$ctrl.importCreatePathMapping"
      aria-label="($ctrl.isForUpdate() ? 'Update' : 'Create') the path-mapping for analytics"
      flex
      ng-change="$ctrl.updateWarnText()"
    >
      {{($ctrl.isForUpdate() ? 'Update' : 'Create')}} the path-mapping for analytics
      <div class="ipsum" style="color: grey">
        {{($ctrl.isForUpdate() ? 'Update' : 'Create')}} each path from the {{($ctrl.isWsdl() ? 'WSDL' : 'swagger')}} descriptor.
      </div>
      <div class="gv-warn" ng-show="$ctrl.isForUpdate() && $ctrl.importCreatePathMapping">This will overwrite all the path-mappings.</div>
    </md-checkbox>
    <md-checkbox
      ng-model="$ctrl.importCreatePolicyPaths"
      aria-label="($ctrl.isForUpdate() ? 'Update' : 'Create') paths for policies"
      ng-click="$ctrl.importCreateMocks = false"
      flex
      ng-change="$ctrl.updateWarnText()"
    >
      {{($ctrl.isForUpdate() ? 'Update' : 'Create')}} policies on paths
      <div class="ipsum" style="color: grey">
        {{($ctrl.isForUpdate() ? 'Update' : 'Create')}} each path from the {{($ctrl.isWsdl() ? 'WSDL' : 'swagger')}} descriptor.
      </div>
      <div class="gv-warn" ng-show="$ctrl.isForUpdate() && $ctrl.importCreatePolicyPaths">This will overwrite all the policies.</div>
    </md-checkbox>

    <div class="policies" layout="column">
      <md-checkbox
        ng-repeat="policy in $ctrl.policies track by policy.id"
        ng-model="policy.enable"
        aria-label="Apply {{::policy.name}} on paths"
        flex
        ng-change="$ctrl.updateWarnText()"
        ng-disabled="!$ctrl.importCreatePolicyPaths"
      >
        Apply {{::policy.name}} policy
        <div class="ipsum" style="color: grey">
          Apply policy on each path from the {{($ctrl.isWsdl() ? 'WSDL' : 'swagger')}} descriptor.
        </div>
        <div class="gv-warn" ng-show="$ctrl.isForUpdate() && $ctrl.importCreateMocks">This will overwrite all the existing policy.</div>
      </md-checkbox>
    </div>
  </div>
</md-dialog-content>
<div class="gv-error-container" ng-if="$ctrl.importError" style="margin: 0 24px">
  <gv-error error="$ctrl.importError"></gv-error>
</div>
<md-dialog-actions layout="row" class="gv-import-api-actions">
  <div ng-show="$ctrl.hasCancel()">
    <md-button md-no-ink ng-click="$ctrl.cancel()">Cancel</md-button>
  </div>
  <div>
    <md-button
      ng-disabled="!$ctrl.enableImport() && !$ctrl.importTriggered"
      ng-click="$ctrl.importAPI()"
      class="md-raised"
      ng-class="{'md-warn': $ctrl.isForUpdate()}"
      >Import</md-button
    >
  </div>
</md-dialog-actions>
